<?php
namespace Wap\Service;
use Think\Upload;

class UploadService
{
	private static $config = array( 
			"maxSize"	=>	3145728,
			'rootPath'	=>	'./Public/',
			'savePath'	=>	'./Uploads/',
			'autoSub'	=>	true,
			'subName'	=>	array( "date", "Ymd" ),
			"saveName"	=>	array( "uniqid", "painting" ),
			"exts"		=>	array( "jpg", "gif", "png", "jpeg", "JPG", "GIF", "PNG", "JPEG" )
   	);	

	public static function fetch_upload_file()
	{
		$uid = 3;//todo:test;
		$host	=	$_SERVER['HTTP_HOST'];

		$plugin	=	new Upload( self::$config );
		$info	=	$plugin->upload();
		$result	=	array( "uid" => $uid, "error" => 0, "files" => array() );//0:没有错误, TODO:files maxsize 4, pic, pica, picb, picd
		if( !$info ){
			$result['error']	=	$plugin->getError();
		}else{
			foreach( $info as $file )
			{
				$temp	=	explode( ".", self::$config['rootPath'], 2 );	
				$temq	=	explode( "./", $file['savepath'], 2 );	
				array_push( $result['files'], "http://".$_SERVER['HTTP_HOST'].$temp[1].$temq[1].$file["savename"] );
			}
		}
		return $result;
	}
}
?>
